package com.qianguo.shop.base;

import android.app.Application;
import android.text.TextUtils;

import com.baidu.mapapi.SDKInitializer;
import com.eva.androidlibrary.DeviceInfo;
import com.eva.androidlibrary.image.ImageLoader;
import com.eva.androidlibrary.utils.DevUtil;
import com.qianguo.shop.UserManager;
import com.qianguo.shop.api.ShopApi;
import com.eva.androidlibrary.api.entity.UserInfo;

import org.androidannotations.annotations.EApplication;

/**
 * Class description
 *
 * @author GUXIA318
 * @date 2015-09-06 16:33
 */
@EApplication
public class App extends Application {

    private UserInfo mUser;
    private ShopApi mShopApi;
    private ImageLoader mImageLoader;

    @Override
    public void onCreate() {
        super.onCreate();
        // 百度地图在使用SDK各组件之前初始化context信息，传入ApplicationContext
        // 注意该方法要再setContentView方法之前实现
        SDKInitializer.initialize(getApplicationContext());
        //TODO 调试模式
        DevUtil.setDebug(true);
        DeviceInfo.initialize(this);
        mShopApi = ShopApi.getInstance(this);
        mUser = UserManager.getUser(this);
        mImageLoader = ImageLoader.getInstance(this);
    }

    public ImageLoader getGlobalImageLoader() {
        return mImageLoader;
    }

    public UserInfo getUser() {
        if (mUser == null) {
            mUser = UserManager.getUser(this);
        }

        DevUtil.v("Eva", mUser.toString());
        return mUser;
    }

    public void setUser(UserInfo user) {
        mUser = user;
    }

    public boolean isLogin() {
        if (mUser != null && !TextUtils.isEmpty(mUser.getUUID()) && !TextUtils.isEmpty(mUser.getToken())) {
            return true;
        }
        return false;
    }

    public ShopApi getApi() {
        return mShopApi;
    }
}
